package com.smart.controller;

import com.github.pagehelper.PageInfo;
import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.model.request.ManageTempUserRegistrationRequest;
import com.smart.model.request.ProjectRequest;
import com.smart.service.ManageTempUserRegistrationService;
import com.smart.model.vo.ManageTempUserRegistrationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zyh
 */
@RestController
@RequestMapping("/registration/temp")
@Api(value = "项目临时人员登记模块", tags = {"项目临时人员登记模块"})
public class ManageTempUserRegistrationController {

    @Autowired
    private ManageTempUserRegistrationService manageTempUserRegistrationService;

    @WebAccess(login = true)
    @ApiOperation("云监管平台临时人员进出查询-项目建设地点、工程类型查询")
    @GetMapping("/superviseAddress")
    public WebResponse superviseAddress(){
        return WebResponse.build(manageTempUserRegistrationService.superviseAddress());
    }

    @WebAccess(login = true)
    @ApiOperation("云监管平台临时人员进出-项目编号或项目名称查询")
    @PostMapping("/superviseVerify")
    public WebResponse superviseVerify(@RequestBody ProjectRequest request){
        return WebResponse.build(manageTempUserRegistrationService.superviseVerify(request));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管、云服务、云管理平台临时人员进出场记录查询-根据项目查询")
    @PostMapping("/supervisePageQueryTempRecordsByProject")
    public WebResponse<PageInfo<List<ManageTempUserRegistrationVO>>> supervisePageQueryTempRecordsByProject(@SortDefault(sort = "entrance_time",direction = Sort.Direction.DESC) Pageable pageable,
                                                                                                   @RequestBody ManageTempUserRegistrationRequest request) {
        return WebResponse.build(manageTempUserRegistrationService.supervisePageQueryTempRecordsByProject(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("云监管、云管理平台临时人员进出场记录查询-根据人员信息查询")
    @PostMapping("/supervisePageQueryTempRecordsByPerson")
    public WebResponse<PageInfo<List<ManageTempUserRegistrationVO>>> supervisePageQueryTempRecordsByPerson(@SortDefault(sort = "mtur.entrance_time",direction = Sort.Direction.DESC) Pageable pageable,
                                                                                                            @RequestBody ManageTempUserRegistrationRequest request) {
        return WebResponse.build(manageTempUserRegistrationService.supervisePageQueryTempRecordsByPerson(request,pageable));
    }

    @ApiOperation("临时人员入场离场信息保存")
    @PostMapping("/add")
    public WebResponse<Object> add(@Valid @RequestBody ManageTempUserRegistrationRequest request) {
        return WebResponse.build(manageTempUserRegistrationService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("(云监管、云管理)临时人员进出场记录-填写手机号和姓名后查询")
    @PostMapping("/verify")
    public WebResponse<Object> verify(@RequestBody ManageTempUserRegistrationRequest request) {
        return WebResponse.build(manageTempUserRegistrationService.verify(request));
    }

    @ApiOperation("临时人员进出场填写手机号和姓名后查询")
    @PostMapping("/verifyAfterWrite")
    public WebResponse<Object> verifyAfterWrite(@RequestBody ManageTempUserRegistrationRequest request) {
        return WebResponse.build(manageTempUserRegistrationService.verifyAfterWrite(request));
    }
}
